#include "Scene.h"

Scene::Scene(char const* mapfile, char const* colmapfile, char const* floorfile) :
  MapImageFile(mapfile), CollisionMapImageFile(colmapfile), FloorImageFile(floorfile),
  Map(NULL), CollisionMap(NULL), Floor(NULL)
{
  MapRect.x = MAP_POS_X;
  MapRect.y = MAP_POS_Y;
  MapRect.w = MAP_SIZE_X;
  MapRect.h = MAP_SIZE_Y;
}

void Scene::InitScene() {
  if(MapImageFile.length()) {
    if (!Map) Map = IMG_Load(MapImageFile.c_str());
    if (!Map) {
      printf("Unable to load map image: %s\n", SDL_GetError());
      exit(1);
    }
  }

  if(CollisionMapImageFile.length()) {
    if (!CollisionMap) CollisionMap = IMG_Load(CollisionMapImageFile.c_str());
    if (!CollisionMap) {
      printf("Unable to load collision map image: %s\n", SDL_GetError());
      exit(1);
    }
  }

  if(FloorImageFile.length()) {
    if (!Floor) Floor = IMG_Load(FloorImageFile.c_str());
    if (!Floor) {
      printf("Unable to load floor image: %s\n", SDL_GetError());
      exit(1);
    }
  }
}

Scene::~Scene() {
  if (Map) SDL_FreeSurface(Map);
  if (CollisionMap) SDL_FreeSurface(CollisionMap);
  if (Floor) SDL_FreeSurface(Floor);
}

